import RxElement from "../../utils/RxElement";

export default class RxDialog {
  static show() {
    const dialog = this._getDialog(true)
    if (dialog) {
      const div = test_titleText()
      dialog.appendChild(div)
    }
  }

  static hidden() {
    const dialog = this._getDialog()
    let child = null
    if (dialog) {
      child = dialog.childNodes

      for (let i = 0; i < child.length; i++) {
        const e = child.children[i]
        e && e.remove && e.remove()
      }
    }
  }

  static _getDialog(isShow) {
    const dialog = RxElement.getElButtonId('rxdialog')
    let wrap = null
    try {

      if (isShow) {
        dialog.style.display = 'flex'
      } else {
        dialog.style.display = 'none'
      }

      const rxdialog_content = dialog.childNodes[3]
      wrap = rxdialog_content.childNodes[1]
    } catch (error) {
      console.error('rxdialog error=', error)
    }


    // console.log('rxdialog _getDialog wrap=', wrap)
    return wrap
  }
}

function test_titleText() {
  const divRoot = document.createElement('div')
  divRoot.className = 'rxdialog_text'

  const divTitle = document.createElement('div')
  divTitle.className = 'title'
  divTitle.innerText = '标题'

  const divText = document.createElement('div')
  divText.className = 'text'
  divText.innerText = '问题'

  divRoot.appendChild(divTitle)
  divRoot.appendChild(divText)
  return divRoot
}